<?php

	include_once 'db_connect.php';
	
	// get feed test
	include_once 'get_feed.php';
	
	$content = '';
	
	if (!isset($_POST["id"])) {echo $content; die;}
	
	$student_id = $_POST['id'];
	//$student_id = 1;
	
	$feedurl = mysql_query("SELECT feedurl FROM blogs WHERE fk_student_id = $student_id");
	
	$feed = mysql_fetch_object($feedurl);
	
	$blog_array = get_feed_array($feed->feedurl);
	
	// populate accordion
	$content .= '<div class="blogHeader">';
	$content .= '<strong>blog title: '.$blog_array['title'].' | last modified: '.$blog_array['dateModified'].'</strong><br/>';
	$content .= '<strong>author: '.$blog_array['author'].'<label> | status:&nbsp;</label></strong>
	<select>
	  <option>All</option>
	  <option>Reviewed</option>
	  <option>Unreviewed</option>
	  <option>Flagged</option>
	</select>';

	$content .= '</div>';
	$content .= '<div id="accordion">';
	
	for ($i=0; $i < count($blog_array['entries'])-1; $i++) {
		$content .= '<div>';
		$content .= '<h3><a href="#">'.$blog_array['entries'][$i]['title'].'</a></h3>';
		$content .= '<div><a href="'.$blog_array['entries'][$i]['link'].'" target="_blank">'.$blog_array['entries'][$i]['title'].'</a>';
		$content .= ' | last modified: '.$blog_array['entries'][$i]['dateModified'];
		$content .= '<p>'.$blog_array['entries'][$i]['content'].'</p><hr/>';
		
		//pull the unique entry_id
		$entry_id = $blog_array['entries'][$i]['id'];
		
		// find a review for this entry in the db
		$q = mysql_query("SELECT * FROM reviews WHERE entry_id = \"$entry_id\""); 
		
		$review = mysql_fetch_object($q);
		
		$content .= '<p><strong>Reviews and Notes</strong></p>';
		
		if (empty($review)) {
			$entry_text = "Enter notes here";
		}
		else {
			$entry_text = $review->review;
		}
		$content .= '<input type="checkbox" id="'.$entry_id.'" name="flagged" ';
		if ($review->flagged == 1) {
			$content .= ' checked="checked"';
		}
		$content .= '>Flagged</input>';
		$content .= '<input type="checkbox" id="'.$entry_id.'" name="reviewed" ';
		if ($review->reviewed == 1) {
			$content .= ' checked="checked"';
		}
		$content .= '>Reviewed</input><br/>';
		$content .= '<textarea rows="4" cols="60" id="'.$entry_id.'">'.$entry_text.'</textarea><br/><br/>';
		$content .= '<button class="review" id="'.$entry_id.'">save note</button>';
		$content .= '<span id="review"> </span>';
		$content .= '</div></div>';
	}
	$content .=	'<div>';

	echo $content;

?>